using Model;
using System;
using System.Threading;
using System.Windows.Input;

namespace WhackBL
{
    public class MainBl
    {
        public MyCommand command { get;set; }
        public MainModel model { get; set; }
        public MainBl ()
        {
            command = new MyCommand(Hit);
            model = new MainModel();
            model.MoleStatus = new System.Collections.Generic.List<MyBool>(20) {
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            new MyBool(){ Mybool = false},
            };
            Thread timer = new Thread(() => {
                while (true)
                {
                    Random ro = new Random();
                    int i =  ro.Next(20);
                    bool r1 = model.MoleStatus.Contains(new MyBool()) && (model.MoleStatus[i].Mybool == false);
                    if (r1) { 
                        model.MoleStatus[i].Mybool = true; 
                     }
                    Thread.Sleep(1000);
                }
                
            });
          timer.Start();
         }
        public void Hit(Object val) 
        {
            int.TryParse(val.ToString(),out int i);
            if (model.MoleStatus[i].Mybool)
            {

                model.MoleStatus[i].Mybool = false;
            }
        }
    }
}
